<?php

class SiteController extends Controller
{
    public function actionIndex(){
        $this->layout = "web/_main.php";
		$type = isset($_GET['type'])?trim($_GET['type']):"null";
		switch ($type) {
			case 'survey':
				$this->render("web/survey");
				break;

			case 'vote':
                $data = array();
				$this->render("web/vote",$data);
				break;
			
			case 'form':
                $data = array();
				$this->render("web/form",$data);
				break;

			case 'helpcenter':
				//调查索引
				$this->renderPartial("web/helpcenter");
				break;

			case 'login':
				//明细页
				$this->render("web/login");
				break;

			case 'register':
				$this->render("web/register");
				break;

			default:
				$this->render("web/index");
				break;
	    }
	}

    public function actionSurvey()
	{
		$type = isset($_GET['type'])?trim($_GET['type']):"null";
		switch ($type) {
			case 'add':
			 	$data = array();
                $data['survey'] = array();
				$this->render("survey/form",$data);
				break;

			case 'edit':
                $modelSurvey = Survey::model()->findByPk($_GET['id']);
                $data = array();
                $data['survey'] = $modelSurvey->getAttributes();
                $data['survey']['questions'] = $modelSurvey->getQuestions();
				$this->render("survey/form",$data);
				break;
			
			case 'view':
				//本地预览题目
                $modelSurvey = Survey::model()->findByPk($_GET['id']);
                $data = array();
                $data['survey'] = $modelSurvey->getAttributes();
                $data['survey']['questions'] = $modelSurvey->getQuestions();
				$this->render("survey/view",$data);
				break;
			case 'join':
				//参与页面
				$this->render("survey/view");
				break;
			case 'index':
				//调查索引
				$this->renderPartial("survey/index");
				break;
			case 'detail':
				//明细页
				$this->render("survey/detail");
				break;
			case 'analysis':
				//数据分析页面
				$this->render("survey/analysis");
				break;
			case 'tool':
				//开发者工具
				$this->render("survey/tool");
				break;
			case 'list':
			default:
				$this->render("survey/list");
				break;
		}
	}

	public function actionError(){
		 if($error=Yii::app()->errorHandler->error)
        {
            if(Yii::app()->request->isAjaxRequest)
                echo $error['message'];
            else
                $this->render('error', $error);
        }
    }

    public function actionLogin(){

    }
}
